import Vue from 'vue';
// import Vuex from 'vuex';
import Vuex from '../core/mini-vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        count: 0,
    },
    mutations: {
        add(state, num = 1) {
            state.count += num;
        },
    },
    actions: {
        async addAsync(ctx, num = 2) {
            // ... 写异步逻辑
            await new Promise((resolve) => {
                setTimeout(() => {
                    //
                    resolve(true);
                }, 1000);
            });
            // 更新 state
            ctx.commit('add', num);
        },
    },
    getters: {
        sum(state) {
            return `一共是：${state.count}`;
        },
    },
});

export default store;
